package com.meixiang.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.meixiang.R;

/**
 * Created by Administrator on 2016/5/18.
 * 弹出 popupWindow 层
 */
public class CustomPopup extends PopupWindow{

    private WindowManager.LayoutParams lp ;
    public CustomPopup(Context context,final Activity mActivity,View parentView,int height,int mipmap){
        this.setContentView(parentView);
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setHeight(height);
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        lp = mActivity.getWindow().getAttributes();
        lp.alpha = 0.93f; //设置弹出层的透明度
        mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);// 屏幕颜色变暗
        mActivity.getWindow().setAttributes(lp);
        mActivity.getWindow().setWindowAnimations(R.style.alert_dialog_anim_style);
        this.setBackgroundDrawable(ContextCompat.getDrawable(context,mipmap));
        this.update();
        this.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

                lp.alpha = 1f;
                mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                mActivity.getWindow().setAttributes(lp);
            }
        });
        mActivity.getWindow().setWindowAnimations(R.style.popup_anim_style);
        this.setAnimationStyle(R.style.alert_dialog_anim_style); //设置弹出动画
    }

}
